package operation;

import book.BookLise;

import java.util.Scanner;

public class DelOperation implements IOperation {
    @Override
    public void work(BookLise bookLise) {
        System.out.println("删减图书");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你增加查找的图书名字");
        String name = scanner.nextLine();

        for (int i = 0; i < bookLise.getNowSize(); i++) {
            if (name.equals(bookLise.getBooks(i).getName())) {
                int index = i;
                for (int j = index;j < bookLise.getNowSize() - 1; j++) {
                    bookLise.setBooks(bookLise.getBooks(j+1),j);
                }
                bookLise.setNowSize(bookLise.getNowSize() - 1);
                System.out.println("《"+ name + "》" + "删除成功");
                return;
            }
        }
        System.out.println("没有要删的这本书");
    }
}
